<template>
  <div>
    <div v-html="myHtml"/>
  </div>
</template>
<style>

</style>
<script>
import axios from 'axios';
export default{
  // 使用时请使用 :url.sync=""传值
  props: {
    // eslint-disable-next-line vue/require-prop-types
    url: {
      required: true
    }
  },
  data() {
    return {
      myHtml: ''
    };
  },
  watch: {
    url(value) {
      this.load(value);
    }
  },
  mounted() {
    this.load(this.url);
  },
  methods: {
    load(url) {
      if (url && url.length > 0) {
        const param = {
          accept: 'text/html, text/plain'
        };
        const that = this;
        axios.get(url, param).then(function(response) {
          // 处理HTML显示
          that.myHtml = response.data;
        }).catch(function() {
          console.log('访问失败~~~~~~~');
        });
      }
    }
  }
};
</script>
